authApp.value('page','material_student'); 
authApp.controller("studentDataController",function($scope,$http,$cookies,$getQueryString){
	if($getQueryString("isfill")=="2"){
		$scope.schoolId=$getQueryString("schoolId");
		$scope.isHideAction=true;
	}
	$scope.sunjectList=[{'subjectname':"",'gradeNumOne':"",'gradeNumTwo':"",'gradeNumThree':"",'gradeNumFour':"",}]
	$scope.savaInfo=function(type){
		var confirmHtml="是否保存";
		if(type=="sub"){
			confirmHtml="是否提交";
		}
		if(window.confirm(confirmHtml)){
			var methodUrl=apis.insertStudentData;
			var methodStatus="0";
			var alertMsg="保存成功";
			if($getQueryString("isfill")=="1"){
				methodUrl=apis.updateStudentData;
			}else if($getQueryString("isfill")=="0"){
				methodUrl=apis.insertStudentData;
			}else{
				$scope.isHideAction=true;
			}
			if(type=="su"){
				methodStatus="0";
				alertMsg="保存成功";
			}else if(type=="sub"){
				methodStatus="1";
				alertMsg="提交成功";
			}
			var subjectname="";
			var grade="";
			var gradeNumOne="";
			var gradeNumTwo="";
			var gradeNumThree="";
			var gradeNumFour="";
			var wholeNum ="";
			gradeNumOneName=$scope.gradeNumOneName+","+$scope.gradeNumTwoName+","+$scope.gradeNumThreeName+","+$scope.gradeNumFourName;
			angular.forEach($scope.sunjectList,function(list,index,array){
				if(index==array.length-1){
					subjectname+=list.subjectname;
					gradeNumOne+=list.gradeNumOne;
					gradeNumTwo+=list.gradeNumTwo;
					gradeNumThree+=list.gradeNumThree;
					gradeNumFour+=list.gradeNumFour;
					wholeNum+=(parseInt(list.gradeNumOne)+parseInt(list.gradeNumTwo)+parseInt(list.gradeNumThree)+parseInt(list.gradeNumFour));
				}else{
					subjectname+=list.subjectname+",";
					gradeNumOne+=list.gradeNumOne+",";
					gradeNumTwo+=list.gradeNumTwo+",";
					gradeNumThree+=list.gradeNumThree+",";
					gradeNumFour+=list.gradeNumFour+",";
					wholeNum+=(parseInt(list.gradeNumOne)+parseInt(list.gradeNumTwo)+parseInt(list.gradeNumThree)+parseInt(list.gradeNumFour))+",";
				}
			})
			$http({
				method:'post',
				url:methodUrl,
				data:{
					'graduatedStudents':$scope.graduatedStudents,
					'graduatedUndergraduateMajor':$scope.graduatedUndergraduateMajor,
					'graduatedSpecializedSubject':$scope.graduatedSpecializedSubject,
					'schoolAllStudents':$scope.schoolAllStudents,
					'allUndergraduateMajor':$scope.allUndergraduateMajor,
					'allSpecializedSubject':$scope.allSpecializedSubject,
					'inschoolStudents':$scope.inschoolStudents,
					'inschoolUndergraduateMajor':$scope.inschoolUndergraduateMajor,
					'inschoolSpecializedSubject':$scope.inschoolSpecializedSubject,
					'inschoolboy':$scope.inschoolboy,
					'inschoolgirl':$scope.inschoolgirl,
					'teacherQualificationCertificate':$scope.teacherQualificationCertificate,
					'relevantEducationalInstitutions':$scope.relevantEducationalInstitutions,
					'employingUnits':$scope.employingUnits,
					'subjectname':subjectname,
					'grade':gradeNumOneName,
					'gradeNumOne':gradeNumOne,
					'gradeNumTwo':gradeNumTwo,
					'gradeNumThree':gradeNumThree,
					'gradeNumFour':gradeNumFour,
					'wholeNum':wholeNum,
					'status':methodStatus,
					'remark1':$scope.remark1,
					'remark2':$scope.remark2,
					'remark3':$scope.remark3,
					'remark4':$scope.remark4,
					'remark5':$scope.remark5,
					'remark6':$scope.remark6,
					'remark7':$scope.remark7,
					'remark8':$scope.remark8,
					'remark9':$scope.remark9,
					'remark10':$scope.remark10,
					'remark11':$scope.remark11,
					'remark12':$scope.remark12,
					'remark13':$scope.remark13,
					'remark14':$scope.remark14,
				},
			}).success(function(response){
				if(response.code=="000000"){
					alert(alertMsg);
					location.href="../datafill.html";
				}
				$scope.judeAllList=response.data;
			})
		}
	}
	$scope.addSubCollun=function(){
		var addCObj={'subjectname':"",'gradeNumOne':"",'gradeNumTwo':"",'gradeNumThree':"",'gradeNumFour':"",};
		$scope.sunjectList.push(addCObj);
	}
	$scope.deleCollen=function($index){
		$scope.sunjectList.splice($index,1);
	}
	$scope.getInfo=function(){
		$http({
			method:'get',
			url:apis.queryStudentDataBySchoolId2,
			params:{'schoolid':$scope.schoolId},
		}).success(function(response){
			if(response.code=="000000"){
				$scope.graduatedStudents=response.data.authStudentData.graduatedStudents;
				$scope.graduatedUndergraduateMajor=response.data.authStudentData.graduatedUndergraduateMajor;
				$scope.graduatedSpecializedSubject=response.data.authStudentData.graduatedSpecializedSubject;
				$scope.schoolAllStudents=response.data.authStudentData.schoolAllStudents;
				$scope.allUndergraduateMajor=response.data.authStudentData.allUndergraduateMajor;
				$scope.allSpecializedSubject=response.data.authStudentData.allSpecializedSubject;
				$scope.inschoolStudents=response.data.authStudentData.inschoolStudents;
				$scope.inschoolUndergraduateMajor=response.data.authStudentData.inschoolUndergraduateMajor;
				$scope.inschoolSpecializedSubject=response.data.authStudentData.inschoolSpecializedSubject;
				$scope.inschoolboy=response.data.authStudentData.inschoolboy;
				$scope.inschoolgirl=response.data.authStudentData.inschoolgirl;
				$scope.teacherQualificationCertificate=response.data.authStudentData.teacherQualificationCertificate;
				$scope.relevantEducationalInstitutions=response.data.authStudentData.relevantEducationalInstitutions;
				$scope.employingUnits=response.data.authStudentData.employingUnits;
				$scope.remark1=response.data.authStudentData.remark.split("#")[0];
				$scope.remark2=response.data.authStudentData.remark.split("#")[1];
				$scope.remark3=response.data.authStudentData.remark.split("#")[2];
				$scope.remark4=response.data.authStudentData.remark.split("#")[3];
				$scope.remark5=response.data.authStudentData.remark.split("#")[4];
				$scope.remark6=response.data.authStudentData.remark.split("#")[5];
				$scope.remark7=response.data.authStudentData.remark.split("#")[6];
				$scope.remark8=response.data.authStudentData.remark.split("#")[7];
				$scope.remark9=response.data.authStudentData.remark.split("#")[8];
				$scope.remark10=response.data.authStudentData.remark.split("#")[9];
				$scope.remark11=response.data.authStudentData.remark.split("#")[10];
				$scope.remark12=response.data.authStudentData.remark.split("#")[11];
				$scope.remark13=response.data.authStudentData.remark.split("#")[12];
				$scope.remark14=response.data.authStudentData.remark.split("#")[13];
				angular.forEach(response.data.authStudentSubjectMap,function(list,index,array){
					if(index>0){
						var addCObj={'subjectname':"",'gradeNumOne':"",'gradeNumTwo':"",'gradeNumThree':"",'gradeNumFour':"",};
						$scope.sunjectList.push(addCObj);
						$scope.sunjectList[index].subjectname=list.subjectname;
						$scope.sunjectList[index].gradeNumOne=list.gradeNumOne;
						$scope.sunjectList[index].gradeNumTwo=list.gradeNumTwo;	
						$scope.sunjectList[index].gradeNumThree=list.gradeNumThree;
						$scope.sunjectList[index].gradeNumFour=list.gradeNumFour;
					}else{
						$scope.sunjectList[index].subjectname=list.subjectname;
						$scope.sunjectList[index].gradeNumOne=list.gradeNumOne;
						$scope.sunjectList[index].gradeNumTwo=list.gradeNumTwo;	
						$scope.sunjectList[index].gradeNumThree=list.gradeNumThree;
						$scope.sunjectList[index].gradeNumFour=list.gradeNumFour;
					}
					console.log($scope.sunjectList);
				})
				/*subjectname=response.data.authStudentData.
				gradeNumOneName=response.data.authStudentData.
				gradeNumOne=response.data.authStudentData.
				gradeNumTwo=response.data.authStudentData.
				gradeNumThree=response.data.authStudentData.
				gradeNumFour=response.data.authStudentData.
				wholeNum=response.data.authStudentData.*/
			}
			$scope.judeAllList=response.data;
		})
	}
	if($getQueryString("isfill")=="1"||$getQueryString("isfill")=="2"){
		$scope.getInfo();
	}
})
